/**
 * 零件平台---修改设计的JS文件
 */

$(document).ready(function(){
	//updateDesign();//修改设计跳转控制
});

function getPartList(partstype,partsName,carid){ 
	  $.ajax({  
	        type : "POST",  
	        url : CONTEXT_PATH+'front/partDesign/getPartList?partsType='+partstype+'&partsName='+partsName+'&carid='+carid,  
	        dataType : "json",  
	        cache : false,  
	        async : false,  
	        success : function(data) {  
                $(".left-twoImgList.listImgBox").empty();
                
                for(i=0;i<data.length;i++){
                	if(data[i].programmeid==''&&data[i].productid==''&&data[i].modleid==''){
                		$(".left-twoImgList.listImgBox").append(
            					"<div class='left-twoImgBlock leftImgBlock "+(data.id==$("#partsNo").val()? 'activeImg':'')+"'>"+
            					"<div class='left-twoImgBox'><img src='"+FILESERVER_PATH+"?id="+data[i].twoDid+"'/></div>"+
            					"<div class='left-oneImgName'>"+data[i].partsName+"</div>"+
            				        "<input type='hidden' value="+JSON.stringify(data[i])+">"+
            				    "</div>");
                	}else{
                		$(".left-twoImgList.listImgBox").append(
            					"<div class='left-twoImgBlock leftImgBlock "+(data.id==$("#partsNo").val()? 'activeImg':'')+"'>"+
            					"<div class='left-twoImgBox'><img src='"+FILESERVER_PATH+"?id="+data[i].twoDid+"'/></div>"+
            					"<div class='left-oneImgName'>"+data[i].partsName+"</div>"+
            					"<div class='left-imgSign'>图纸</div>"+
            				        "<input type='hidden' value="+JSON.stringify(data[i])+">"+
            				    "</div>");
                	}
                }
                imgSelectControl();
                $("#partstype").val(partstype);
                
	        }  
	    }); 
	
}

var isSubmit = false; 

function submitForm(designame){
	   var id=$("#id").val();
	   if (isSubmit) {  
	        return  
	   }  

	   var	url=CONTEXT_PATH+'front/partDesign/addMyPart?designame='+designame;
	   	   
	   isSubmit = true;  
	   
	   if(id==''){
		   jAlert("未选中零部件类型","提示");
	   }else{
		   $('#partDesignform').ajaxSubmit({
			   dataType: "json",  
			   url: url,
			   type : "POST",
			   success: function(data) {  
				   if(data.result){
					   $("#partModifyModal").modal('show');
					   isSubmit = false;               	
				   }else{
					   jAlert("创建失败！","提示");
				   }
 
			   }   
		  
		   }); 
	   }
}

function download(designid){
        var id=designid;
	if(id==''){
		jAlert("该设计文件是空的，请添加零件设计后再下载","提示");
	}else{
		$("#designid").val(designid);
	    $("input[name='chose']").prop("checked",false);
		$("#loadModal").modal('show');
	}
	
}

function submitDownload(authentication){
	
	if(authentication=='1'){
		if ($("input[name='chose']:checked").length!=0) {
			$("#downloadForm").submit();
			$("#loadModal").modal('hide');
		}else{
			jAlert("请先至少选中一个","提示");
		}
	}else{//认证未通过
		if($("input[name='chose']:checked").length!=0) {
			if($("#chose2").is(":checked")||$("#chose3").is(":checked")||$("#chose4").is(":checked")||$("#chose5").is(":checked")){
				jAlert("未认证用户只能下载2d文档","提示");
			}else if($("#chose1").is(":checked")){
				$("#downloadForm").submit();
				$("#loadModal").modal('hide');
			}
		}else{
			jAlert("请先至少选中一个","提示");
		}
	}
		
}

function del(id){
	jConfirm('确定要删除吗?', '操作确认', function(r) {
		if(r){
			//$("#loading").showLoading(); 
			$.ajax({
				type : "POST",
				url : CONTEXT_PATH+'front/partDesign/delPartDesign?id='+id,
				dataType : "json",  
		        cache : false,  
		        async : false,
		        success : function(data) {
		        	if(data.result){
		        		jAlert("删除成功","提示", function(r) {
		        			  window.location.reload();
		        		 });
		        	}else{
		        		//$('#loading').hideLoading();
		        		 jAlert("删除时出错","提示");
		        	}
		        }
			});
		}
	});
	
}